package com.sikadwafastdaisfondturbo.pretloan.pro

import com.sikadwafastdaisfondturbo.pretloan.base.BaseFragment
import com.sikadwafastdaisfondturbo.pretloan.utils.config.Configs
import com.sikadwafastdaisfondturbo.pretloan.utils.http.HttpHelper
import com.sikadwafastdaisfondturbo.pretloan.utils.http.IHttpCallback
import org.json.JSONObject
import java.io.File

/**
 * Sikadwa
 * @Author wwdeng
 * @CreateTime: 2024/5/20 16:10
 * @Annotation：
 */
abstract class ProFragment: BaseFragment() {

    /**
     * 获取APP配置信息
     */
    fun getCommonObject(): JSONObject{
        return JSONObject(Configs.getSPString(Configs.SPKEY.SIKADWA_COMMON))
    }

    /**
     * 设置是否需要请求完成隐藏加载框，适用于 多个接口同时调用
     */
    fun setNeedHideLoading(isNeedHideLoading: Boolean){
        val act = context as ProActivity
        act.isNeedHideLoading = isNeedHideLoading
    }

    /**
     * 客服dialog
     */
    fun showKefuDialog(eventRemark: String){
        val act = context as ProActivity
        act.showKefuDialog(eventRemark)
    }

    /**
     * 选择语言
     */
    fun showSikadwaProLangDialog(eventRemark: String,isCancel: Boolean = true,isCancelTouch: Boolean = true,onCheckSuccess: () -> Unit){
        val act = context as ProActivity
        act.showSikadwaProLangDialog(eventRemark,isCancel,isCancelTouch,onCheckSuccess)
    }

    /**
     * 显示个人中心dialiog
     */
    fun showPersonalDialog(eventRemark: String){
        val act = context as ProActivity
        act.showPersonalDialog(eventRemark)
    }

    /**
     * 退出登录
     */
    fun onLoginOutAction(){
        val act = context as ProActivity
        act.onLoginOutAction()
    }

    /**
     * 开始网络请求 Post
     * @param url       : 接口地址
     * @param params    : 参数
     * @param callback  :  回调
     */
    open fun postAction(url: String, params: JSONObject, callback: IHttpCallback) {
        val act = context as ProActivity
        act.postAction(url,params,callback)
    }

    /**
     * POST方式请求 (文件上传)
     *
     * @param url
     * @param file
     * @param callback
     */
    open fun uploadFileAction(url: String, file: File, callback: IHttpCallback){
        val act = context as ProActivity
        act.uploadFileAction(url,file,callback)
    }

    /**
     * 添加埋点
     */
    open fun addEvent(eventName: String,remark: String){
        HttpHelper.addEvent(eventName,remark)
    }
}